/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.game.web.category;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.game.entity.category.HkGameShopCategory;
import com.thinkgem.jeesite.modules.hk.game.service.category.HkGameShopCategoryService;

/**
 * 游戏商铺分类Controller
 * @author 罗天文
 * @version 2018-10-20
 */
@Controller
@RequestMapping(value = "${adminPath}/game/category/hkGameShopCategory")
public class HkGameShopCategoryController extends BaseController {

	@Autowired
	private HkGameShopCategoryService hkGameShopCategoryService;
	
	@ModelAttribute
	public HkGameShopCategory get(@RequestParam(required=false) String id) {
		HkGameShopCategory entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkGameShopCategoryService.get(id);
		}
		if (entity == null){
			entity = new HkGameShopCategory();
		}
		return entity;
	}
	
	@RequiresPermissions("game:category:hkGameShopCategory:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkGameShopCategory hkGameShopCategory, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkGameShopCategory> page = hkGameShopCategoryService.findPage(new Page<HkGameShopCategory>(request, response), hkGameShopCategory); 
		model.addAttribute("page", page);
		return "hk/game/category/hkGameShopCategoryList";
	}

	@RequiresPermissions("game:category:hkGameShopCategory:view")
	@RequestMapping(value = "form")
	public String form(HkGameShopCategory hkGameShopCategory, Model model) {
		model.addAttribute("hkGameShopCategory", hkGameShopCategory);
		return "hk/game/category/hkGameShopCategoryForm";
	}

	@RequiresPermissions("game:category:hkGameShopCategory:edit")
	@RequestMapping(value = "save")
	public String save(HkGameShopCategory hkGameShopCategory, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkGameShopCategory)){
			return form(hkGameShopCategory, model);
		}
		hkGameShopCategoryService.save(hkGameShopCategory);
		addMessage(redirectAttributes, "保存游戏商铺分类成功");
		return "redirect:"+Global.getAdminPath()+"/game/category/hkGameShopCategory/?repage";
	}
	
	@RequiresPermissions("game:category:hkGameShopCategory:edit")
	@RequestMapping(value = "delete")
	public String delete(HkGameShopCategory hkGameShopCategory, RedirectAttributes redirectAttributes) {
		hkGameShopCategoryService.delete(hkGameShopCategory);
		addMessage(redirectAttributes, "删除游戏商铺分类成功");
		return "redirect:"+Global.getAdminPath()+"/game/category/hkGameShopCategory/?repage";
	}

}